package com.uwo.house.util;

import com.github.wxpay.sdk.WXPayUtil;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;

/**
 * Created by dell on 2017/12/9.
 */
public class WeiXinSign {

    public static String generateSignature(Map<String, String> data, String key) throws Exception {
        Set<String> keySet = data.keySet();
        String[] keyArray = (String[])keySet.toArray(new String[keySet.size()]);
        Arrays.sort(keyArray);
        StringBuilder sb = new StringBuilder();
        String[] var5 = keyArray;
        int var6 = keyArray.length;

        for(int var7 = 0; var7 < var6; ++var7) {
            String k = var5[var7];
            if(!k.equals("sign") && ((String)data.get(k)).trim().length() > 0) {
                sb.append(k).append("=").append(((String)data.get(k)).trim()).append("&");
            }
        }

        sb.append("key=").append(key);
        String sign = WXPayUtil.MD5(sb.toString()).toUpperCase();
        return sign;
    }
}
